import app from '@/app'
import { get } from '@/api/erp/bills'

import base from '@/app/model'

// 继承总模型
const model = new base;

model.get = () => {
  return new Promise((resolve, jeject) => {
    app.ui.loading()
    get(model.getData()).then(res => {
      model.setList(res.data)
      // 分页
      model.setData(Object.assign(model.getData(), {
        page: res.current_page,
        page_size: res.per_page,
        page_total: res.total
      }))
      resolve(res)
    }).catch(res => {
      jeject(res)
    }).finally(() => {
      app.ui.loadingClose()
    })
  })
}

model.page = (page) => {
  model.getData().page = page
  model.get()
}

export default model